<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>从用户提供的函数创建训练数据结构。</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.fann-create-train-from-callback" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">fann_create_train_from_callback</h1>
  <p class="verinfo">(PECL fann &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">fann_create_train_from_callback</span> &mdash; <span class="dc-title">从用户提供的函数创建训练数据结构。</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.fann-create-train-from-callback-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>fann_create_train_from_callback</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$num_data</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$num_input</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$num_output</code></span>
   , <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$user_function</code></span>
   ) : <span class="type">resource</span></div>

  <p class="para rdfs-comment">
   从用户提供的函数创建训练数据结构。当训练数据可数，用户需要构造一个用来接收训练数据集(包括输入，输出)数量和返回值为集合的函数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.fann-create-train-from-callback-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<code class="parameter">num_data</code></dt>

    <dd>

     <p class="para">
      训练数据的数量。
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">num_input</code></dt>

    <dd>

     <p class="para">
      每个训练数据的输入数。
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">num_output</code></dt>

    <dd>

     <p class="para">
      每个训练数据的输出数。
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">user_function</code></dt>

    <dd>

     <p class="para">
      用户提供的函数包含以下参数：
      <ul class="simplelist">
       <li class="member"><em>num</em> - 训练数据集的数量。</li>
       <li class="member"><em>num_input</em> - 数量数据的输入数。</li>
       <li class="member"><em>num_output</em> - 数量数据的输出数。</li>
      </ul>
     </p>
     <p class="para">
      函数应该返回一个包含<em>input</em> 和 <em>output</em> 键的数组，并且这两个键的值分别表示输入输出的值(皆为数组)。
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.fann-create-train-from-callback-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para"> Returns a train data <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> on success, or <strong><code>FALSE</code></strong> on error.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.fann-create-train-from-callback-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4507">
    <p><strong>Example #1 <span class="methodname"><strong>fann_create_train_from_callback()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">create_train_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$num_data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_output</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"input"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"output"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">array_fill</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_output</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;);<br />}<br /><br /></span><span style="color: #0000BB">$num_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$num_input&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$num_output&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$train_data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fann_create_train_from_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$num_data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_input</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$num_output</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"create_train_callback"</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$train_data</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Do&nbsp;something&nbsp;with&nbsp;$train_data<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.fann-create-train-from-callback-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="fann_read_train_from_file.html" class="function" rel="rdfs-seeAlso">fann_read_train_from_file()</a> - 读取存储训练数据的文件。</span></li>
    <li class="member"><span class="function"><a href="fann_train_on_data.html" class="function" rel="rdfs-seeAlso">fann_train_on_data()</a> - 在整个数据集上训练一段时间。</span></li>
    <li class="member"><span class="function"><a href="fann_destroy_train.html" class="function" rel="rdfs-seeAlso">fann_destroy_train()</a> - 销毁训练数据。</span></li>
    <li class="member"><span class="function"><a href="fann_save_train.html" class="function" rel="rdfs-seeAlso">fann_save_train()</a> - 将训练结构体保存至文件。</span></li>
   </ul>
  </p>
 </div>



</div></div></div></body></html>